#include "GraphicsLineItem.h"

GraphicsLineItem::GraphicsLineItem()
    : m_p1(0.0, 0.0)
    , m_p2(0.0, 0.0)
{
}

GraphicsLineItem::~GraphicsLineItem()
{
}

void
GraphicsLineItem::setLine(const QPointF &p1, const QPointF &p2)
{
    if(p1 != m_p1)
    {
        m_p1 = p1;
        emit headChanged(p1);
    }

    if(p2 != m_p2)
    {
        m_p2 = p2;
        emit headChanged(p2);
    }
}

void
GraphicsLineItem::setLine(const QLineF &ln)
{
    if(ln.p1() != m_p1)
    {
        m_p1 = ln.p1();
        emit headChanged(ln.p1());
    }

    if(ln.p2() != m_p2)
    {
        m_p2 = ln.p2();
        emit headChanged(ln.p2());
    }
}

void
GraphicsLineItem::setHead(const QPointF &h)
{
    if(h == m_p1)
        return;
    m_p1 = h;
    emit headChanged(h);
}

void
GraphicsLineItem::setTail(const QPointF &t)
{
    if(t == m_p2)
        return;
    m_p2 = t;
    emit tailChanged(t);
}

void
GraphicsLineItem::render()
{
    glBegin(GL_LINES);
        glVertex2f(m_p1.x(), m_p1.y());
        glVertex2f(m_p2.x(), m_p2.y());
    glEnd();
}
